/*     */ package com.zimbra.cs.service.mail;
/*     */ 
/*     */ import com.zimbra.common.mailbox.Color;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.SoapProtocol;
/*     */ import com.zimbra.cs.mailbox.Flag;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.OperationContext;
/*     */ import com.zimbra.cs.mime.ParsedContact;
/*     */ import com.zimbra.cs.service.util.ItemId;
/*     */ import com.zimbra.cs.service.util.ItemIdFormatter;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.List;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ContactActionHelper
/*     */   extends ItemActionHelper
/*     */ {
/*     */   private ParsedContact mParsedContact;
/*     */   
/*     */   public static ContactActionHelper UPDATE(ZimbraSoapContext zsc, OperationContext octxt, Mailbox mbox, List<Integer> ids, ItemId iidFolder, String flags, String[] tags, Color color, ParsedContact pc)
/*     */     throws ServiceException
/*     */   {
/*  38 */     ContactActionHelper ca = new ContactActionHelper(octxt, mbox, zsc.getResponseProtocol(), ids, ItemActionHelper.Op.UPDATE);
/*  39 */     ca.setIidFolder(iidFolder);
/*  40 */     ca.setFlags(flags);
/*  41 */     ca.setTags(tags);
/*  42 */     ca.setColor(color);
/*  43 */     ca.setParsedContact(pc);
/*  44 */     ca.schedule();
/*  45 */     return ca;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public void setParsedContact(ParsedContact pc)
/*     */   {
/*  53 */     assert (this.mOperation == ItemActionHelper.Op.UPDATE);
/*  54 */     this.mParsedContact = pc;
/*     */   }
/*     */   
/*     */   ContactActionHelper(OperationContext octxt, Mailbox mbox, SoapProtocol responseProto, List<Integer> ids, ItemActionHelper.Op op) throws ServiceException {
/*  58 */     super(octxt, mbox, responseProto, ids, op, MailItem.Type.CONTACT, true, null);
/*     */   }
/*     */   
/*     */   protected void schedule()
/*     */     throws ServiceException
/*     */   {
/*  64 */     switch (this.mOperation) {
/*     */     case UPDATE: 
/*  66 */       if (!this.mIidFolder.belongsTo(getMailbox())) {
/*  67 */         throw ServiceException.INVALID_REQUEST("cannot move item between mailboxes", null);
/*     */       }
/*     */       
/*  70 */       if (this.mIidFolder.getId() > 0) {
/*  71 */         getMailbox().move(getOpCtxt(), this.itemIds, this.type, this.mIidFolder.getId(), this.mTargetConstraint);
/*     */       }
/*  73 */       if ((this.mTags != null) || (this.mFlags != null)) {
/*  74 */         getMailbox().setTags(getOpCtxt(), this.itemIds, this.type, Flag.toBitmask(this.mFlags), this.mTags, this.mTargetConstraint);
/*     */       }
/*  76 */       if (this.mColor != null) {
/*  77 */         getMailbox().setColor(getOpCtxt(), this.itemIds, this.type, this.mColor);
/*     */       }
/*  79 */       if (this.mParsedContact != null) {
/*  80 */         for (int id : this.itemIds) {
/*  81 */           getMailbox().modifyContact(getOpCtxt(), id, this.mParsedContact);
/*     */         }
/*     */       }
/*     */       break;
/*     */     default: 
/*  86 */       throw ServiceException.INVALID_REQUEST("unknown operation: " + this.mOperation, null);
/*     */     }
/*     */     
/*  89 */     StringBuilder successes = new StringBuilder();
/*  90 */     for (int id : this.itemIds) {
/*  91 */       successes.append(successes.length() > 0 ? "," : "").append(this.mIdFormatter.formatItemId(id));
/*     */     }
/*  93 */     this.mResult = successes.toString();
/*     */   }
/*     */   
/*     */   public String toString()
/*     */   {
/*  98 */     StringBuilder toRet = new StringBuilder(super.toString());
/*  99 */     if ((this.mOperation == ItemActionHelper.Op.UPDATE) && 
/* 100 */       (this.mParsedContact != null)) {
/* 101 */       toRet.append(" Fields=").append(this.mParsedContact.getFields());
/*     */     }
/*     */     
/* 104 */     return toRet.toString();
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/mail/ContactActionHelper.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */